package com.example.smartagriculture.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.smartagriculture.controller.DTO.AllEnvironmentalInformationDTO;
import com.example.smartagriculture.entity.AllEnvironmentalInformation;
import com.example.smartagriculture.mapper.AllEnvironmentalInformationMapper;
import com.example.smartagriculture.service.IAllEnvironmentalInformationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * AllEnvironmentalInformationServiceImpl 服务实现类
 * @author 张芸博
 * @since 2024-12-28
 */
@Service
public class AllEnvironmentalInformationServiceImpl extends ServiceImpl<AllEnvironmentalInformationMapper, AllEnvironmentalInformation> implements IAllEnvironmentalInformationService {
    @Resource
AllEnvironmentalInformationMapper allEnvironmentalInformationMapper;
    @Override
    public AllEnvironmentalInformationDTO getTen() {
        double t=0,h=0,l=0;
        AllEnvironmentalInformationDTO allEnvironmentalInformationDTO = new AllEnvironmentalInformationDTO();
        ArrayList<AllEnvironmentalInformation> arrayList = new ArrayList(allEnvironmentalInformationMapper.getLatestTenMsg());
        for (int i = 0; i < arrayList.size(); i++) {
            t=arrayList.get(i).getTemperature()+t;
            h=arrayList.get(i).getHumidity()+h;
            l=arrayList.get(i).getLightIntensity()+l;
        }
        allEnvironmentalInformationDTO.setTemperature(t/arrayList.size());
        allEnvironmentalInformationDTO.setHumidity(h/arrayList.size());
        allEnvironmentalInformationDTO.setLightIntensity(l/arrayList.size());
        return allEnvironmentalInformationDTO;
    }

    @Override
    public List<AllEnvironmentalInformationDTO> getMonthAvg() {
        List<AllEnvironmentalInformationDTO> list = allEnvironmentalInformationMapper.getMonthAvg();
        return list;
    }

    @Override
    public List<AllEnvironmentalInformationDTO> getYearAvg() {
        List<AllEnvironmentalInformationDTO> list = allEnvironmentalInformationMapper.getMonthAvg();
        return list;
    }

    @Override
    public List<AllEnvironmentalInformationDTO> getDayAvg() {
        List<AllEnvironmentalInformationDTO> list = allEnvironmentalInformationMapper.getMonthAvg();
        return list;
    }
}
